package ch.wanandroid.lib.ui.base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @author wulinpeng
 * @datetime: 18/9/17 下午11:57
 * @description:
 */
public abstract class BaseFragment extends Fragment {

    protected Unbinder mUnBinder;
    protected View mRootView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        int layoutId = getLayoutId();
        // 不绑定mRoot到container，返回mRoot后系统自动绑定
        mRootView = inflater.inflate(layoutId, container, false);
        initView(mRootView);
        return mRootView;
    }

    protected abstract int getLayoutId();

    protected void initView(View view) {
        mUnBinder = ButterKnife.bind(this, view);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mUnBinder.unbind();
    }

    /**
     * Activity传递过来的返回事件，如果处理了返回true
     * @return
     */
    public boolean onBackPressed() {
        return false;
    }

}
